****************************************************************************
* File-Name: 	code.do
* Date:		 	11/20/2023
* Author: 		Fred Batista and Felipe Nunes
* Purpose: 		Analysis of survey and survey-experiment data for Who is Responsible for the Emergency Aid? (LAPS 65/4)
* Data used: 	data.dta
* Data Output:	None	*/
****************************************************************************

***** VARIABLES IN DATASET
* not all variables are included due to their proprietary status.

* P4: Presidential approval pre-treatment
* P6: Congressional evaluation pre-tratment
* P18: Benefit recipient status
* P19: responsibility for program
* P20: experimental tratamento
* P21: response to vignette (not used)
* P22: Presidential approval post-treatment
* P23: Congressional evaluation post-tratment
* P32: income
* P33: religious affiliation
* P37: second round vote for president  in 2018
* AV: sex
* AW: age
* AX: regiion


***** RECODES

**** AID RECIPIENT STATUS VARIABLE (no, denied, requested)

* MAIN: no and denied as 0, received or waiting as 1

encode P18, gen(aid2)

recode aid2 (1 4=0) (2 3=1)

* ALTERNATIVE: no as 0, denied as 1, received or waiting as 2

encode P18, gen(aid)

recode aid (1=0) (2 3=2) (4=1)

**** MODERATOR: RESPONSIBILITY

encode P19, gen(resp)

recode resp (2 3 4=0) (1=1) (5=2)

gen respbolso = resp

recode respbolso (2=1) (else=0)

gen respcong = resp

recode respcong (1=1) (else=0)

* interaction term between aid2 and respbolso

gen aid2respbolso = aid2*respbolso

* interaction term between aid2 and respcong

gen aid2respcong = aid2*respcong

**** EXPERIMENTAL TREATMENT

encode P20, gen(treat)

recode treat (1=1) (2=0)

*** DEPENDENT VARIABLE: BOLSONARO�S APPROVAL (DK as neutral)

* evaluation of bolsonaro�s job performance

* pre-treatment

encode P4, gen(approval1)

recode approval1 (1=5) (2=3) (3=0) (4=2) (5=4) (6=1) (7=6) 

gen approval1_01 = approval1/6

* post-treatment

encode P22, gen(approval2)

recode approval2  (1=5) (2=3) (3=0) (4=2) (5=4) (6=1) (7=6) 

gen approval2_01 = approval2/5

* diff_approval

gen diff_approval = approval2 - approval1

*** DEPENDENT VARIABLE: CONGRESSO OPINION (DK as neutral)

* pre-treatment

encode P6, gen(cong1)

recode cong1 (1=5) (2=3) (3=0) (4=2) (5=4) (6=1) (7=6)

gen cong1_01 = cong1/5

* post-treatment

encode P23, gen(cong2)

recode cong2 (1=5) (2=3) (3=0) (4=2) (5=4) (6=1) (7=6) 

gen cong2_01 = cong2/5

* diff_cong

gen diff_cong = cong2 - cong1

**** OTHER VARIABLES

* 2018 vote (null and absent as neutral category)

encode P37, gen(vote18)

**** CONTROLS

* religion

encode P33, gen(religion)

gen catholic = religion

recode catholic (1=1)(else=0)

gen protestant = religion

recode protestant (2 6=1) (else=0)

* income

encode P32, gen(income)

recode income (1=0) (2=6) (3=1) (4=5) (5=2) (6=3) (7=4) (8=7)  (9=.)

* income 3 categories)

gen income2 = income

recode income2 (3 4 5 6 7=3) (.=.)

* sex (male=1)

encode AV, gen(male)

replace male = male - 1

* age

encode AW, gen(age)

replace age = age + 15

recode age (71=72) (72=74) (73=81) (74=93)

* region

encode AX, gen(region)


***** DESCRIPTIVE STATISTICS

tab region, gen(reg)

tab income, gen(inc)

tab income2, gen(inc2_)

tab vote18, gen(pastvote)

* Table A1

summarize approval1 approval2 cong1 cong2 aid2 0.resp respbolso respcong treat inc1 inc2 inc3 inc4 inc5 inc6 inc7 inc8 age male protestant catholic reg1 reg2 reg3 reg4 reg5


***** ANALYSES: OBSERVATIONAL

*** Coarsened Exact Matching (excludes income categories with no benefiaries, over 10 MW) 

* running propensity scores

cem male age (40 50 60 70) region income2 catholic protestant if income<6, tr(aid2) autocuts(fd)

* diagnostics (Table A3)

tab male aid2 if income<6, col nolabel
tab male aid2 if income<6 [iweight=cem_weights], col nolabel

summarize age if aid2==0 & income<6
summarize age if aid2==1 & income<6

summarize age if aid2==0 & income<6 [iweight=cem_weights]
summarize age if aid2==1 & income<6 [iweight=cem_weights]

tab reg1 aid2 if income<6, col nolabel
tab reg1 aid2 if income<6 [iweight=cem_weights], col nolabel

tab reg2 aid2 if income<6, col nolabel
tab reg2 aid2  if income<6 [iweight=cem_weights], col nolabel

tab reg3 aid2 if income<6, col nolabel
tab reg3 aid2  if income<6 [iweight=cem_weights], col nolabel

tab reg4 aid2 if income<6, col nolabel
tab reg4 aid2  if income<6 [iweight=cem_weights], col nolabel

tab reg5 aid2 if income<6, col nolabel
tab reg5 aid2  if income<6 [iweight=cem_weights], col nolabel

tab income2 aid2 if income<6, col nolabel
tab income2 aid2  if income<6 [iweight=cem_weights], col nolabel

tab catholic aid2 if income<6, col nolabel
tab catholic aid2  if income<6 [iweight=cem_weights], col nolabel

tab protestant aid2 if income<6, col nolabel
tab protestant aid2  if income<6 [iweight=cem_weights], col nolabel

* model for approval of president (Table 2s and A2 column 1)

reg approval1 aid2 cem_weights male age i.region i.income2 catholic protestant [aweight=cem_weights] if income<6

esizereg aid2 

power twomeans 0  0.177198, n(657)

power twomeans 0   0.177198, power(.8)

* models for approval of president conditional of responsibilization (Tables 2 and A2 columns 3 and 3)

reg approval1 aid2 respbolso cem_weights male age i.region i.income2 catholic protestant [aweight=cem_weights] if income<6

reg approval1 aid2 respbolso aid2respbolso cem_weights male age i.region i.income2 catholic protestant [aweight=cem_weights] if income<6

esizereg aid2respbolso

power twomeans 0   0.401842, n(657)

* model for approval of congress (Tables 2 and A2 column 4)

reg cong1 aid2 cem_weights male age i.region i.income2 catholic protestant [aweight=cem_weights] if income<6

esizereg aid2 

power twomeans 0  0.170564,  n(657)

power twomeans 0  0.170564, power(.8)

* models for approval of president conditional of responsibilization (Tables 2 and A2 columns 5 and 6)

reg cong1 aid2 respcong cem_weights male age i.region i.income2 catholic protestant [aweight=cem_weights] if income<6

reg cong1 aid2 respcong aid2respcong cem_weights male age i.region i.income2 catholic protestant [aweight=cem_weights] if income<6


*** is treatment variable correlated with political preferences (and, hence, the DV)?

* using vote in 2018 (Table A6)

tab aid2 vote18 if income<6, col chi

* using responsibilization (Table A7) 

tab aid2 resp if income<6, col chi



*** Alternative: OLS (Table A5)

* president

reg approval1 aid2  male age i.region i.income2 catholic protestant if income<6

reg approval1 aid2  respbolso male age i.region i.income2 catholic protestant if income<6

reg approval1 aid2 respbolso aid2respbolso  male age i.region i.income2 catholic protestant  if income<6

* congress

reg cong1 aid2  male age i.region i.income2 catholic protestant if income<6

reg cong1 aid2  respcong male age i.region i.income2 catholic protestant if income<6

reg cong1 aid2 respcong aid2respcong  male age i.region i.income2 catholic protestant  if income<6


*** Alternative: propensity score matching

* running propensity score

psmatch2 aid2 male age i.region i.income2 catholic protestant if income<6, out(approval1) logit

* diagnostics (Table A4)

tab male aid2 if income<6, col nolabel
tab male aid2 if income<6 [iweight=_pscore], col nolabel

summarize age if aid2==0 & income<6
summarize age if aid2==1 & income<6

summarize age if aid2==0 & income<6 [iweight=_pscore]
summarize age if aid2==1 & income<6 [iweight=_pscore]

tab reg1 aid2 if income<6, col nolabel
tab reg1 aid2 if income<6 [iweight=_pscore], col nolabel

tab reg2 aid2 if income<6, col nolabel
tab reg2 aid2  if income<6 [iweight=_pscore], col nolabel

tab reg3 aid2 if income<6, col nolabel
tab reg3 aid2  if income<6 [iweight=_pscore], col nolabel

tab reg4 aid2 if income<6, col nolabel
tab reg4 aid2  if income<6 [iweight=_pscore], col nolabel

tab reg5 aid2 if income<6, col nolabel
tab reg5 aid2  if income<6 [iweight=_pscore], col nolabel

tab income2 aid2 if income<6, col nolabel
tab income2 aid2  if income<6 [iweight=_pscore], col nolabel

tab catholic aid2 if income<6, col nolabel
tab catholic aid2  if income<6 [iweight=_pscore], col nolabel

tab protestant aid2 if income<6, col nolabel
tab protestant aid2  if income<6 [iweight=_pscore], col nolabel

* model 

* model for approval of president

reg approval1 aid2 cem_weights male age i.region i.income2 catholic protestant [aweight=_pscore] if income<6

esizereg aid2 

power twomeans 0  0.181871, n(579)

* model for approval of president conditional of responsibilization

reg approval1 aid2 respbolso aid2respbolso cem_weights male age i.region i.income2 catholic protestant [aweight=_weight] if income<6

esizereg aid2respbolso

power twomeans 0  0.235941, n(579)

* model for approval of congress

reg cong1 aid2 cem_weights male age i.region i.income2 catholic protestant [aweight=_weight] if income<6

esizereg aid2 

power twomeans 0  0.231978, power(.8)


* model for approval of president conditional of responsibilization

reg cong1 aid2 respcong aid2respcong cem_weights male age i.region i.income2 catholic protestant [aweight=_weight] if income<6

esizereg aid2respcong

power twomeans 0  0.189110, n(579)


*** Alternative IV through OLS (Table A8)

reg approval1 i.aid  male age i.region i.income2 catholic protestant if income<6

reg cong1 i.aid  male age i.region i.income2 catholic protestant if income<6


*** testing differences by gender through OLS (Table A9)

reg approval1 i.aid2##i.male age i.region i.income2 catholic protestant if income<6

reg cong1 i.aid2##i.male age i.region i.income2 catholic protestant if income<6



*** ANALYSES: EXPERIMENTAL

* BALANCE CHECKS (Table A10)

reg treat approval1 cong1 aid2 respbolso respcong reg2 reg3 reg4 reg5 inc2_2 inc2_3 inc2_4 age male protestant catholic, robust

test approval1 cong1 aid2 respbolso respcong reg2 reg3 reg4 reg5 inc2_2 inc2_3 age male protestant catholic


* ATEs (Tables 3 and A11)

reg approval2 treat i.income2 male age i.region catholic protestant cong1 approval1 aid2

esizereg treat

power twomeans 0  0.025847 , power(.8)

reg cong2 treat i.income2 male age  i.region catholic protestant  cong1 approval1 aid2

esizereg treat

power twomeans 0 0.202205, power(.8)


* ATEs by starting level of approval (Figure 1 and Tables A12 and A13)

sort approval1

by approval1: reg approval2 treat i.income2 male age  i.region catholic protestant cong1 aid2

matrix y1 = (.1778387  \.2114896 \ .1358849 \-.5700075\ -.1511268\-.2018977\-.0553572)

matrix lb1 = (.030367  \ -.1573153  \-.3491896\-1.705317\-.6385821\-.5124391\ -.4820918)

matrix ub1 = (.3253104\.5802945\.6209594\.5653023\.3363286\.1086436\.3713775)

matrix x1 = (1\2\3\4\5\6\7)

matrix matrix1 = y1, lb1, ub1, x1

matrix list matrix1

svmat matrix1, name(a)

eclplot a1 a2 a3 a4, ciopts(blcolor(black) msize(vtiny)) estopts(color(black) m(circle)) yline(0, lcolor(black) lpattern(dash)) ylabel(-1.75 " " -1.5 "-1.5" -1 "-1.0" -0.5 "-0.5" 0 "0.0" 0.5 "0.5" 1 "1.0" 1.5 "1.5", nogrid noticks) xlabel(0.7 " " 1 `" "Terrible" "(n=373)" "' 2 `" "Bad" "(n=124)" "' 3 `" "Reg. Neg." "(n=97)" "' 4 `" "Neutral" "(n=17)" "' 5 `" "Reg. Pos." "(n=131)" "' 6 `" "Good" "(n=114)" "' 7 `" "Great" "(n=94)" "' 7.3 " ", noticks labsize(small) labgap(2) tl(2) nogrid) yscale(lc(white)) title({bf:Approval of President},size(vlarge) bmargin(4)) ytitle("Treatment Effect") xtitle("Pre-Treatment Approval of President")  ysize(5) xsize(8) graphregion(color(white)) plotregion(style(none)) xscale(noextend) yscale(noextend) saving(fig2a)

sort cong1

by cong1: reg cong2 treat i.income2 male age  i.region catholic protestant approval1 aid2

matrix y2 = (.5611156    \.5467579 \  .6319638 \ .5579848 \ .2068655\.0682267 \-.3903907)

matrix lb2 = ( .156783   \ .0697957  \.2562465\ -.1281891  \-.0946757\-.3504872\-1.570085)

matrix ub2 = (.9654483\1.02372\ 1.007681\ 1.244159\.5084067\.4869405\.7893035)

matrix x2 = (1\2\3\4\5\6\7)

matrix matrix2 = y2, lb2, ub2, x2

matrix list matrix2

svmat matrix2, name(b)

eclplot b1 b2 b3 b4, ciopts(blcolor(black) msize(vtiny)) estopts(color(black) m(circle)) yline(0, lcolor(black) lpattern(dash)) ylabel(-1.75 " " -1.5 "-1.5" -1 "-1.0" -0.5 "-0.5" 0 "0.0" 0.5 "0.5" 1 "1.0" 1.5 "1.5", nogrid noticks) xlabel(0.7 " " 1 `" "Terrible" "(n=196)" "' 2 `" "Bad" "(n=171)" "' 3 `" "Reg. Neg." "(n=195)" "' 4 `" "Neutral" "(n=61)" "' 5 `" "Reg. Pos." "(n=211)" "' 6 `" "Good" "(n=85)" "' 7 `" "Great" "(n=31)" "' 7.3 " ", noticks labsize(small) labgap(2) tl(2) nogrid) yscale(lc(white)) title({bf:Approval of Congress},size(vlarge) bmargin(4)) ytitle("Treatment Effect") xtitle("Pre-Treatment Approval of Congress")  ysize(5) xsize(8) graphregion(color(white)) plotregion(style(none)) xscale(noextend) yscale(noextend) saving(fig2b)

graph combine fig2a.gph fig2b.gph, graphregion(color(white)) plotregion(style(none)) iscale(1) ysize(4) xsize(10) 



* ATEs by resp (Figure 2 and Table A14)

reg approval2 treat i.income2 male age  i.region catholic protestant cong1 approval1 aid2 if resp==1

reg approval2 treat i.income2 male age  i.region catholic protestant cong1 approval1 aid2 if resp==2

reg approval2 treat i.income2 male age  i.region catholic protestant cong1 approval1 aid2 if resp==0

matrix y3 = (-.0311579  \.106694 \ -.0197871  )

matrix lb3 = ( -.2062698  \ -.0540523 \-.457283)

matrix ub3 = ( .143954\ .2674403\.4177089)

matrix x3 = (1\2\3)

matrix matrix3 = y3, lb3, ub3, x3

matrix list matrix3

svmat matrix3, name(c)

eclplot c1 c2 c3 c4, ciopts(blcolor(black) msize(vtiny)) estopts(color(black) m(circle)) yline(0, lcolor(black) lpattern(dash)) ylabel(-.5 "-.0.5" 0 "0.0" 0.5 "0.5" 1 "1.0" 1.5 "1.5", nogrid noticks) xlabel(0.7 " " 1 "Congress" 2 "President" 3 "Other/DK" 3.3 " ", noticks labsize(small) labgap(2) tl(2) nogrid) yscale(lc(white)) title({bf:Approval of President},size(vlarge) bmargin(4)) ytitle("Treatment Effect") xtitle("Pre-Treatment: Responsible for Program")  ysize(5) xsize(8) graphregion(color(white)) plotregion(style(none)) xscale(noextend) yscale(noextend) saving(fig3a)

reg cong2 treat i.income2 male age  i.region catholic protestant cong1 approval1 aid2 if resp==1

reg cong2 treat i.income2 male age  i.region catholic protestant cong1 approval1 aid2 if resp==2

reg cong2 treat i.income2 male age  i.region catholic protestant cong1 approval1 aid2 if resp==0

matrix y4 = ( .2947334  \.300556  \  .7378172 )

matrix lb4 = ( .0596511 \ .0634535 \.2034732)

matrix ub4 = ( .5298157\ .5376584\ 1.272161)

matrix x4 = (1\2\3)

matrix matrix4 = y4, lb4, ub4, x4

matrix list matrix4

svmat matrix4, name(d)

eclplot d1 d2 d3 d4, ciopts(blcolor(black) msize(vtiny)) estopts(color(black) m(circle)) yline(0, lcolor(black) lpattern(dash)) ylabel(-.5 "-0.5" 0 "0.0" 0.5 "0.5" 1 "1.0" 1.5 "1.5", nogrid) xlabel(0.7 " " 1 `" "Congress" "(n=461)" "' 2 `" "President" "(n=361)" "' 3 `" "Other/DK" "(n=128)" "' 3.3 " ", noticks labsize(small) labgap(2) tl(2) nogrid) yscale(lc(white)) title({bf:Approval of Congress},size(vlarge) bmargin(4)) ytitle("Treatment Effect") xtitle("Pre-Treatment: Responsible for Program")  ysize(5) xsize(8) graphregion(color(white)) plotregion(style(none)) xscale(noextend) yscale(noextend) saving(fig3b)


graph combine fig3a.gph fig3b.gph, graphregion(color(white)) plotregion(style(none)) iscale(1) ysize(4) xsize(10) 


* unadjusted ATEs (Table A15)

reg approval2 treat 

reg cong2 treat 


* ATES FOR THOSE RECEIVING THE BENEFIT (Table A16)

*ATEs

reg approval2 i.treat  i.income2 male age  i.region catholic protestant cong1 approval1 if aid2==1

reg cong2 i.treat i.income2 male age  i.region catholic protestant cong1 approval1 if aid2==1


****RESULTS BY GENDER (Table A17)

reg approval2 i.treat##i.male i.income2 age i.region catholic protestant cong1 approval1 aid2

reg cong2 i.treat##i.male i.income2 age i.region catholic protestant  cong1 approval1 aid2

*****


********************************** END OF CODE***************************************************
